package a05_双指针法;


/**
 * <p>
 * a05_反转链表
 * </p>
 *
 * @author flyduck
 * @since 2024-07-18
 */
public class a05_反转链表复习1 {

    public static ListNode reverseList(ListNode head) {
        ListNode prev = null;
        ListNode curr = head;
        while (curr != null) {
            ListNode temp = curr.next;

            curr.next = prev;

            prev = curr;
            curr = temp;
        }
        return prev;
    }

    public static void main(String[] args) {
        ListNode head = new ListNode(1);
        head.next = new ListNode(2);
        head.next.next = new ListNode(3);
        head.next.next.next = new ListNode(4);
        head.next.next.next.next = new ListNode(5);
        ListNode listNode = reverseList(head);
        System.out.println(listNode);
    }
}
